package com.zyk.scaffold.shardingsphere.rw.business.write.controller;

import com.zyk.scaffold.common.utils.RandomUtils;
import com.zyk.scaffold.core.domain.Result;
import com.zyk.scaffold.shardingsphere.rw.repositorys.entity.TAddress;
import com.zyk.scaffold.shardingsphere.rw.repositorys.interfaces.TAddressRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

@RestController
@RequestMapping("/write")
public class WriteController {

    @Autowired
    private TAddressRepository tAddressRepository;

    private AtomicLong atomicLong = new AtomicLong(1L);

    @PostMapping("/save")
    public Result<Boolean> save(){
        TAddress tAddress = new TAddress();
        tAddress.setAddressId(atomicLong.getAndIncrement());
        tAddress.setAddressName(RandomUtils.getCharAndNumr(12));
        boolean save = tAddressRepository.save(tAddress);
        return Result.ok(save);
    }
}
